        package Wiimote;


        use strict;
        use warnings;

        require Exporter;
        require DynaLoader;


sub get_wiimote_keys_home {
   return substr( dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ), 0,1) ;
}

sub get_wiimote_keys_minus {
   return substr( dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ), 3,1) ;
}

sub get_wiimote_keys_a {
   return substr( dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ), 4,1) ;
}

sub get_wiimote_keys_b {
   return substr( dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ), 5,1) ;
}

sub get_wiimote_keys_1 {
   return substr( dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ), 6,1) ;
}

sub get_wiimote_keys_2 {
   return substr( dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ), 7,1) ;
}

sub get_wiimote_keys_plus {
   return substr( dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ), 11,1) ;
}

sub get_wiimote_keys_up {
   return substr( dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ), 12,1) ;
}

sub get_wiimote_keys_down {
   return substr( dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ), 13,1) ;
}

sub get_wiimote_keys_right {
   return substr( dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ), 14,1) ;
}

sub get_wiimote_keys_left {
   return substr( dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ), 15,1) ;
}



sub get_wiimote_keys_bits {
   return dec2bin16(Wiimote::get_wiimote_keys_raw_bits() ) ;
}

sub dec2bin16 {
    my $str = unpack("B32", pack("N", shift));
    #$str =~ s/^0+(?=\d)//;   # otherwise you'll get leading zeros
    #return $str;
    return substr($str,16,16);
}

        our @ISA = qw(Exporter DynaLoader);
        # Items to export into callers namespace by default. Note: do not export
        # names by default without a very good reason. Use EXPORT_OK instead.
        # Do not simply export all your public functions/methods/constants.
        our @EXPORT = qw(

        );
        our $VERSION = '0.01';

        bootstrap Wiimote $VERSION;

        # Preloaded methods go here.

        # Autoload methods go after __END__, and are processed by the autosplit program.

        1;
        __END__
        # Below is the stub of documentation for your module. You better edit it!
=head1 NAME

Wiimote

=head1 SYNOPSIS

This is a perl interface to the C library libwiimote ( http://sourceforge.net/projects/libwiimote/ ).
It implements most of the API.

Methods:

 wiimote_connect( ID OF YOUR WIIMOTE ): pass in the id of your wiimote such as '00:19:1D:75:CC:30'.  Returns 0 on success

 wiimote_update : updates the wiimote.  Should be called often

 set_wiimote_rumble:  starts/stops rumble.  Pass in 1 to start, 0 to stop

get_wiimote_tilt_x
get_wiimote_tilt_y
get_wiimote_tilt_z

get_wiimote_axis_x
get_wiimote_axis_y
get_wiimote_axis_z

get_wiimote_ext_nunchuk_axis_x
get_wiimote_ext_nunchuk_axis_y
get_wiimote_ext_nunchuk_axis_z

 get_wiimote_ext_nunchuk_joyx
 get_wiimote_ext_nunchuk_joyy

 Below return 0 or 1 depending on if key is pressed:

 get_wiimote_keys_home

 get_wiimote_keys_minus

 get_wiimote_keys_a

 get_wiimote_keys_b

 get_wiimote_keys_1

 get_wiimote_keys_2

 get_wiimote_keys_plus

 get_wiimote_keys_up

 get_wiimote_keys_down

 get_wiimote_keys_right

 get_wiimote_keys_left

 get_wiimote_keys_bits



=head1 Example 

use Wiimote;

Wiimote::wiimote_connect('00:19:1D:75:CC:30');

while ( Wiimote::is_open() ) {

    Wiimote::wiimote_update();

    print "Wiimote Key bits: " . Wiimote::get_wiimote_keys_bits();

}


=head1 author

   Chad Phillips chad@chadphillips.org http://www.windmeadow.com

 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 


=cut
